$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + '/workflow/actTask/getTaskList',
        datatype: "json",
        colModel: [
            {label: '任务编号', name: 'id', index: 'id', width: 80},
            {label: '名称', name: 'name', index: 'name', width: 80},
            {label: '部署id', name: 'processInstanceId', index: 'processInstanceId', width: 80},
            {
                label: '操作', width: 80, formatter: function (value, options, row) {
                return '<a class="btn btn-modify"  onclick=vm.detail(\"' + row.id + '\",\"' + row.processInstanceId + '\") style="display: inline;">详情</a>' +
                    '&nbsp;&nbsp;&nbsp;<a class="btn btn-delete"  onclick=vm.getProcessInfo(\"' + row.id + '\") style="display: inline;">审核</a>'+
                    '&nbsp;&nbsp;&nbsp;<a class="btn btn-delete"  onclick=vm.getHistoryInfo(\"' + row.processInstanceId + '\") style="display: inline;">历史</a>'
            }
            }
        ],
        viewrecords: true,
        height: 365,
        rowNum: 10,
        rowList: [10, 30, 50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth: true,
        multiselect: false,
        pager: "#jqGridPager",
        jsonReader: {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames: {
            page: "page",
            rows: "limit",
            order: "order"
        },
        gridComplete: function () {
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "hidden"});
        }
    });
});

var vm = new Vue({
    el: '#rrapp',
    data: {
        q: {},
        showList: true,
        title: null,
        model: {}
    },
    methods: {
        query: function () {
            vm.reload();
        },
        add: function () {
            vm.showList = false;
            vm.title = "新增";
            vm.model = {};
        },
        update: function (event) {
            var id = getSelectedRow();
            if (id == null) {
                return;
            }
            vm.showList = false;
            vm.title = "修改";
            vm.getInfo(id)
        },
        save: function (event) {
            var url = "workflow/actModel/createActModel";
            $.ajax({
                type: "POST",
                url: baseURL + url,
                // url: url,
                contentType: "application/json",
                data: JSON.stringify(vm.model),
                success: function (r) {
                    if (r.code === 0) {
                        alert('操作成功', function (index) {
                            vm.reload();
                        });
                    } else {
                        alert(r.msg);
                    }
                }
            });
        },
        detail: function (id) {
            var storage = window.localStorage;
            var rowData = $('#jqGrid').jqGrid('getRowData', id);
            var processInstanceId = rowData.processInstanceId;
            window.location.href = '/workflow/actFlow/instance?executionId=' + processInstanceId;
        },
        getInfo: function (id) {
            $.get(baseURL + "legalprovisions/info/" + id, function (r) {
                vm.legalProvisions = r.legalProvisions;
            });
        },
        getProcessInfo: function (id) {
            var storage = window.localStorage;
            storage.setItem("processId", id);
            window.location.href = "backloginfo.html";
        },
        getHistoryInfo: function (processInstanceId) {
            vm.showList = false;
            vm.model = {};
            $("#legaljqGrid").jqGrid({
                url: baseURL + '/workflow/actFlow/histoicFlow?procInsId='+processInstanceId,
                datatype: "json",
                colModel: [
                    {label: 'Id', name: 'processInstanceId', index: 'processInstanceId', width: 80},
                    {label: '节点Id', name: 'activityId', index: 'activityId', width: 80},
                    {label: '节点名称', name: 'activityName', index: 'activityName', width: 80},
                    {label: '节点类型', name: 'activityType', index: 'activityType', width: 80},
                    {label: '审批人', name: 'assignee', index: 'assignee', width: 80},
                    {label: '开始时间', name: 'startTime', index: 'startTime', width: 80},
                    {label: '结束时间', name: 'endTime', index: 'endTime', width: 80}
                ],
                viewrecords: true,
                height: 365,
                rowNum: 10,
                rowList: [10, 30, 50],
                rownumbers: true,
                rownumWidth: 45,
                autowidth: true,
                multiselect: false,
                pager: "#legaljqGridPager",
                jsonReader: {
                    root: "page.list",
                    page: "page.currPage",
                    total: "page.totalPage",
                    records: "page.totalCount"
                },
                prmNames: {
                    page: "page",
                    rows: "limit",
                    order: "order"
                },
                gridComplete: function () {
                    //隐藏grid底部滚动条
                    $("#legaljqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "hidden"});
                    $("#legaljqGrid").setGridWidth($(window).width() * 0.99);
                }
            });
        },
        goBack: function () {
            window.location.href = "backlogprocess.html";
        },
        reload: function (event) {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                page: page,
                postData: {'name': vm.q.name}
            }).trigger("reloadGrid");
        }
    }
});